package com.example.football.service;


import com.example.football.mapper.PeopleMapper;
import com.example.football.mapper.YuyueMapper;
import com.example.football.pojo.People;
import com.example.football.pojo.Peoplelikestar;
import com.example.football.pojo.Result;
import com.example.football.pojo.Yuyue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class YuyueServiceImpl {

    @Autowired
    private YuyueMapper userMapper;

    public Result insertYuyue(Yuyue yuyue){
        Result result=new Result();
        result.setSuccess(false);
        result.setDetail(null);
        try {
            Yuyue userByName = userMapper.findYuyueBydate(yuyue);
            if(userByName!=null){
                //如果查询到 说明存在
                result.setMsg("已添加");
            }else {
                userMapper.insertYuyue(yuyue);
                result.setMsg("插入成功");
                result.setSuccess(true);
                result.setDetail(yuyue);
            }
        }catch (Exception e){
            result.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    public Result findYuyueBySite(Yuyue yuyue){
        Result result=new Result();
        result.setSuccess(false);
        result.setDetail(null);
        try {

            result.setMsg("查找成功");
            result.setSuccess(true);
            List<Yuyue> yuyues =  userMapper.findYuyueBysite(yuyue);
            result.setDetail(yuyues);
        }catch (Exception e){
            result.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    public Result updateYuyueByTeam1(Yuyue yuyue){
        Result result=new Result();
        result.setSuccess(false);
        result.setDetail(null);
        try {

            result.setMsg("更新成功");
            result.setSuccess(true);
            userMapper.updateYuyueByteam1(yuyue);
            result.setDetail(yuyue);
        }catch (Exception e){
            result.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    public Result updateYuyueByTeam2(Yuyue yuyue){
        Result result=new Result();
        result.setSuccess(false);
        result.setDetail(null);
        try {

            result.setMsg("更新成功");
            result.setSuccess(true);
            userMapper.updateYuyueByteam2(yuyue);
            result.setDetail(yuyue);
        }catch (Exception e){
            result.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    public Result findYuyueByTeam(Yuyue yuyue){
        Result result=new Result();
        result.setSuccess(false);
        result.setDetail(null);
        try {

            result.setMsg("查找成功");
            result.setSuccess(true);
            List<Yuyue> yuyues =  userMapper.findYueyueByteam(yuyue);
            result.setDetail(yuyues);
        }catch (Exception e){
            result.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }
}
